<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<?php
include('helper/url_helper.php');
include('helper/simple_html_dom.php');
include('adodb/adodb.inc.php');
include('config.php');
$db = ADONewConnection($_config['dbdriver']);
$db->Connect($_config['server'],$_config['username'],$_config['password'],$_config['database']);
$db->Execute('SET character_set_results=utf8');
$db->Execute('SET collation_connection=utf8_unicode_ci');
$db->Execute('SET NAMES utf8');
$links = get_link();
if($links)
{
	
	$url = 'http://www.kpopza.com';
	foreach ($links as $key => $link)
	{
		$html = file_get_html($link);
		// $data['title'] = $html->find('h1[class=post-title]',0)->plaintext;
		// $data['title'] = trim(html_entity_decode($data['title'],ENT_QUOTES,'UTF-8'));
		//$data['detail'] = $html->find('div.entry-content',0)->find('img',1);
		//$data['detail'] .= $html->find('div.entry-content span.fullpost',0)->innertext;
		$data['detail'] = $html->find('div.entry-content',0)->my_callback;
		//echo $data['detail'] = trim(html_entity_decode($data['detail'],ENT_QUOTES,'UTF-8'));
		// //$db->AutoExecute('kpopza',$data,'INSERT');
		// // print "<br>".++$key." $link insert";
		// unset($html);
		// unset($data);
	}
	//print "<br>".count($links)." records updated";
	
}
else
{
	print('<br>no data updated');
}
?>
</body>
</html>
<?

/*---------------------------------------function-----------------------------------------------*/

function my_callback($element) {
        if ($element->tag=='img' || $element->tag=='span')
                $element->outertext = '';
	} 

function get_link()
{
	global $db;
	$html = file_get_html('http://www.kpopza.com');
	foreach($html->find('h2.post-title a') as $key => $data)
	{
		if($key == 0 )$next = $data->href;
		if (!preg_match("/^\//", $data->href)) 
		{
			$slug = clean_url($data->plaintext);
			$check = $db->GetOne('select slug from kpopza where slug = ?',array($slug));
			if(!$check)
			{
				$feed[] =  $data->href;
			}
			else
			{
				if(isset($feed))
				{
					sort($feed);
					return $feed;
				}
				else
				{
					return false;
				}
			}
				
		} 
	}
	if(isset($feed))
	{
		sort($feed);
		return $feed;
	}
	else
	{
		return false;
	}
}
?>